package com.appspot.aliga.presentation;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.appspot.aliga.LeagueTableEntry;
import com.appspot.aliga.R;

public class LeagueTableEntryAdapter extends BaseAdapter {
    private List<LeagueTableEntry> entries;
    private LayoutInflater inflater;

    public LeagueTableEntryAdapter(Context context, List<LeagueTableEntry> list) {
        // Caches the LayoutInflater for quicker use
        this.inflater = LayoutInflater.from(context);

        this.entries = list;
    }

    public int getCount() {
        return this.entries.size();
    }

    public Object getItem(int position) {
        return this.entries.get(position);
    }

    public long getItemId(int position) {
        if (position < getCount() && position >= 0) {
            return position;
        }
        return 0;
    }

    public View getView(int position, View view, ViewGroup viewGroup) {
        if (view == null) { // If the View is not cached
            // Inflates the Common View from XML file
            view = this.inflater.inflate(R.layout.leaguetable_row, null);
        }

        LeagueTableEntry entry = entries.get(position);

        ((TextView)view.findViewById(R.id.leaguetablerow_team)).setText(entry.getPosition() + ". " + entry.getTeamName());
        ((TextView)view.findViewById(R.id.leaguetablerow_games)).setText(entry.getGamesPlayed() + "");
        ((TextView)view.findViewById(R.id.leaguetablerow_goales)).setText(entry.getGoals() + "");
        ((TextView)view.findViewById(R.id.leaguetablerow_points)).setText(entry.getPoints() + "");


        return view;
    }
}
